#include <iostream>
#include <SDL/SDL.h>

#include "sprite.h"
#include "peca_explosao.h"

#define GRAVIDADE 0.00025
/******************************************************************************
    Construtor()
    Define os valores iniciais da peca    
******************************************************************************/
Peca_Explosao::Peca_Explosao(int tipo, float vy0, float vx0, double x, double y) {
    if (tipo == 1) {
        img = Sprite::Get("cinza")->surface;
    } else if (tipo == 2) {
        img = Sprite::Get("amarelo")->surface;
    } else if (tipo == 3) {
        img = Sprite::Get("roxo")->surface;
    } else if (tipo == 4) {
        img = Sprite::Get("verde")->surface;
    } else if (tipo == 5) {
        img = Sprite::Get("vermelho")->surface;
    } else if (tipo == 6) {
        img = Sprite::Get("azul")->surface;
    } else if (tipo == 7) {
        img = Sprite::Get("laranja")->surface;
    }
    
    this->x = x;
    this->y = y;
    this->y0 = y;
    this->vy0 = vy0;
    this->vx0 = vx0;
    this->t = 0;
}

/******************************************************************************
    Atualizar(dt)
    Atualiza a posicao da peca na tela
******************************************************************************/
void Peca_Explosao::Atualizar(Uint32 dt){
    //cout << "Atualizando: " << y << " " << y0 << " "  << v0 << " "  << t << " "  << t*t;
    t += dt;
    y = y0 + vy0 * t + (GRAVIDADE/2) * t * t;
    
    x += dt * vx0;
    //cout << "\n";
}

/******************************************************************************
    Draw(Tela)
    Faz a peca se desenhar na tela
******************************************************************************/
void Peca_Explosao::Draw(SDL_Surface *tela) {
    //cout << "Desenhando x = "<< (int)x << ", y = " << (int)y << "\n";
    int xi = (int)x;
    int yi = (int)y;
    SDL_Rect dst = {xi, yi, 0, 0};
    //cout << "\t\t Blit \n"; cout.flush();

    SDL_BlitSurface(img, NULL, tela, &dst );
}


/******************************************************************************
    Destrutor()
******************************************************************************/
Peca_Explosao::~Peca_Explosao(void) {

}
